home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / Macintosh Common Lisp Related / interfaces / TextServices.lisp < prev   
Encoding:
Text File  |  1993-09-16  |  16.1 KB  |  401 lines  |  [TEXT/CCL2]

  1. ;;       
  2. ;;    File:        TextServices.p
  3. ;;
  4. ;;    Copyright:    © 1983-1993 by Apple Computer, Inc.
  5. ;;                All rights reserved.
  6. ;;
  7. ;;    Version:    System 7.1 for ETO #11
  8. ;;    Created:    Tuesday, March 30, 1993 18:00
  9. ;;
  10. ;;      adaptated to MCL 2.0 by Gilles Serasset, GETA-IMAG, France
  11.  
  12. (in-package :traps)
  13.  
  14. ;       $IFC UNDEFINED UsingIncludes
  15. ;       $SETC UsingIncludes := 0
  16. ;       $ENDC
  17.  
  18. ;       $IFC NOT UsingIncludes
  19. ; UNIT TextServices;
  20. ; INTERFACE
  21. ;       $ENDC
  22.  
  23. ;       $IFC UNDEFINED UsingTextServices
  24. ;       $SETC UsingTextServices := 1
  25.  
  26. ;       $I+
  27. ;       $SETC UsingTextServices := UsingIncludes
  28. ;       $SETC UsingIncludes := 1
  29. ;       $IFC UNDEFINED UsingTypes
  30. ;       $I $$Shell(PInterfaces)Types.p
  31. (require-interface 'TYPES)
  32. ;       $ENDC
  33. ;       $IFC UNDEFINED UsingEvents
  34. ;       $I $$Shell(PInterfaces)Events.p
  35. (require-interface 'EVENTS) 
  36. ;       $ENDC
  37. ;       $IFC UNDEFINED UsingMenus
  38. ;       $I $$Shell(PInterfaces)Menus.p
  39. (require-interface 'Menus) 
  40. ;       $ENDC
  41. ;       $IFC UNDEFINED UsingAppleEvents
  42. ;       $I $$Shell(PInterfaces)AppleEvents.p
  43. (require-interface 'AppleEvents) 
  44. ;       $ENDC
  45. ;       $IFC UNDEFINED UsingErrors
  46. ;       $I $$Shell(PInterfaces)Errors.p
  47. (require-interface 'Errors) 
  48. ;       $ENDC
  49. ;       $IFC UNDEFINED UsingComponents
  50. ;       $I $$Shell(PInterfaces)Components.p
  51. (require-interface 'Components) 
  52. ;       $ENDC
  53. ;       $SETC UsingIncludes := UsingTextServices
  54.  
  55.  
  56. (defconstant $kTSMVersion 1);        Version of Text Services Manager 
  57. (defconstant $kTextService :|tsvc|);        Component type for component description 
  58. (defconstant $kInputMethodService :|inpm|);        Component subtype for component description 
  59.  
  60. (defconstant $bTakeActiveEvent 15);        Bit set if the component takes activate events 
  61. (defconstant $bScriptMask #x00007F00);        Bits 8 - 14 
  62. (defconstant $bLanguageMask #x000000FF);        Bits 0 - 7 
  63. (defconstant $bScriptLanguageMask (+ $bScriptMask $bLanguageMask));       Bits 0 - 14 
  64.  
  65. ;        Hilite styles ... 
  66. (defconstant $kCursorPosition 1);        specify cursor position 
  67. (defconstant $kRawText 2);        specify range of raw text 
  68. (defconstant $kSelectedRawText 3);        specify range of selected raw text 
  69. (defconstant $kConvertedText 4);        specify range of converted text 
  70. (defconstant $kSelectedConvertedText 5);        specify range of selected converted text 
  71.  
  72. ;  Apple Event constants
  73.  
  74. (defconstant $kTextServiceClass $kTextService);        Event class 
  75. (defconstant $kUpdateActiveInputArea :|updt|);        Update the active inline area 
  76. (defconstant $kPos2Offset :|p2st|);        Convert global coordinates to character position 
  77. (defconstant $kOffset2Pos :|st2p|);        Convert character position to global coordinate 
  78. (defconstant $kShowHideInputWindow :|shiw|);        show or hide the input window 
  79.  
  80. ;    Event keywords ... 
  81.  
  82. (defconstant $keyAETSMDocumentRefcon :|refc|);        TSM document refcon 
  83.  
  84. (defconstant $keyAEServerInstance :|srvi|);        Server instance 
  85. (defconstant $keyAETheData :|kdat|);        typeText 
  86. (defconstant $keyAEScriptTag :|sclg|);        Script tag 
  87. (defconstant $keyAEFixLength :|fixl|)
  88. (defconstant $keyAEHiliteRange :|hrng|);        Hilite range array 
  89. (defconstant $keyAEUpdateRange :|udng|);        Update range array 
  90. (defconstant $keyAEClauseOffsets :|clau|);        Clause offsets array 
  91. (defconstant $keyAECurrentPoint :|cpos|);        Current point 
  92. (defconstant $keyAEDragging :|bool|);        Dragging flag 
  93. (defconstant $keyAEOffset :|ofst|);        Offset 
  94. (defconstant $keyAERegionClass :|rgnc|);        Region class 
  95. (defconstant $keyAEPoint :|gpos|);        Current point 
  96. (defconstant $keyAEBufferSize :|buff|);        Buffer size to get the text 
  97. (defconstant $keyAERequestedType :|rtyp|);        Requested text type 
  98. (defconstant $keyAEMoveView :|mvvw|);        Move view flag 
  99. (defconstant $keyAELength :|leng|);        Length 
  100. (defconstant $keyAENextBody :|nxbd|);        Next or previous body 
  101.  
  102. ;        optional keywords for Offset2Pos-- 28Mar92 
  103.  
  104. (defconstant $keyAETextFont :|ktxf|)
  105. (defconstant $keyAETextPointSize :|ktps|)
  106. (defconstant $keyAETextLineHeight :|ktlh|)
  107. (defconstant $keyAETextLineAscent :|ktas|)
  108. (defconstant $keyAEAngle :|kang|)
  109.  
  110. ;        optional keyword for Pos2Offset
  111.  
  112. (defconstant $keyAELeftSide :|klef|);        type Boolean 
  113.  
  114. ;        optional keyword for kShowHideInputWindow
  115.  
  116. (defconstant $keyAEShowHideInputWindow :|shiw|);        type Boolean 
  117.  
  118. ;        keyword for PinRange  
  119.  
  120. (defconstant $keyAEPinRange :|pnrg|);        <#6> 
  121.  
  122.  
  123. ;        Desc type ... 
  124.  
  125. (defconstant $typeComponentInstance :|cmpi|);        Component instance 
  126. (defconstant $typeTextRangeArray :|tray|);        Text range array 
  127. (defconstant $typeOffsetArray :|ofay|);        Offset array 
  128. (defconstant $typeIntlWritingCode :|intl|);        Script code 
  129. (defconstant $typeQDPoint :|QDpt|);        QuickDraw point 
  130. (defconstant $typeAEText :|tTXT|);        Apple Event text 
  131. (defconstant $typeText :|TEXT|);        Plain text 
  132.  
  133. (defconstant $typeTextRange :|txrn|);        <#6> 
  134.  
  135.  
  136. ;       Error codes
  137.  
  138.  
  139. (defconstant $tsmComponentNoErr 0);        Component result   no error 
  140.  
  141. (defconstant $tsmUnsupScriptLanguageErr -2500)
  142. (defconstant $tsmInputMethodNotFoundErr -2501)
  143. (defconstant $tsmNotAnAppErr -2502);        Not an application error 
  144. (defconstant $tsmAlreadyRegisteredErr -2503);        Attemp to register again 
  145. (defconstant $tsmNeverRegisteredErr -2504);        App never registered.  (Not TSM Aware) 
  146. (defconstant $tsmInvalidDocIDErr -2505);        Invalid TSM documentation ID 
  147. (defconstant $tsmTSMDocBusyErr -2506);        Document is still active 
  148. (defconstant $tsmDocNotActiveErr -2507);        Document is not active 
  149. (defconstant $tsmNoOpenTSErr -2508);        No open text service 
  150. (defconstant $tsmCantOpenComponentErr -2509);        Can't open the component 
  151. (defconstant $tsmTextServiceNotFoundErr -2510);        No text service found 
  152. (defconstant $tsmDocumentOpenErr -2511);        There are open documents 
  153. (defconstant $tsmUseInputWindowErr -2512);        Not TSM aware because an input window is being used 
  154. (defconstant $tsmTSHasNoMenuErr -2513);        The Text Service has no menu 
  155. (defconstant $tsmTSNotOpenErr -2514);        Text service is not open 
  156. (defconstant $tsmComponentAlreadyOpenErr -2515);        Text service already open for document 
  157.  
  158. (defconstant $tsmInputMethodIsOldErr -2516);        Returned by GetDefaultInputMethod 
  159. (defconstant $tsmScriptHasNoIMErr -2517);        Script has no input method or is using old input method 
  160. (defconstant $tsmUnsupportedTypeErr -2518);        unSupported interface type error 
  161. (defconstant $tsmUnknownErr -2519);        Any other errors 
  162.  
  163. (defconstant $kTSMOutsideOfBody 1)
  164. (defconstant $kTSMInsideOfBody 2)
  165. (defconstant $kTSMInsideOfActiveInputArea 3)
  166.  
  167. (defconstant $kNextBody 1)
  168. (defconstant $kPreviousBody 2)
  169.  
  170. (defconstant $errOffsetInvalid -1800)
  171. (defconstant $errOffsetIsOutsideOfView -1801)
  172. (defconstant $errTopOfDocument -1810)
  173. (defconstant $errTopOfBody -1811)
  174. (defconstant $errEndOfDocument -1812)
  175. (defconstant $errEndOfBody -1813)
  176.  
  177.  
  178. ;; Types
  179.  
  180. (def-mactype :TextRangeHandle (find-mactype :handle))
  181. (def-mactype :TextRangePtr (find-mactype :pointer))
  182.  
  183. (defrecord (TextRange :handle)     ;  typeTextRange
  184.   (fStart :signed-long)
  185.   (fEnd :signed-long)
  186.   (fHiliteStyle :signed-integer)
  187.   )
  188.  
  189. (def-mactype :TextRangeArrayHandle (find-mactype :handle))
  190. (def-mactype :TextRangeArrayPtr (find-mactype :pointer))
  191. (defrecord (TextRangeArray :handle)       ; typeTextRangeArray
  192.   (fNumOfRanges    :signed-integer)
  193.   (fRange (:array :TextRange 1))
  194.   )
  195.  
  196. (def-mactype :OffsetArrayHandle    (find-mactype :handle))
  197. (def-mactype :OffsetArrayPtr (find-mactype :pointer))
  198. (defrecord (OffsetArray :handle)    ; typeOffsetArray
  199.   (fNumOfOffsets :signed-integer)
  200.   (fOffset (:array :signed-long 1) )
  201. )
  202.  
  203.  
  204. (def-mactype :TextServicesInfoPtr (find-mactype :pointer))
  205. (defrecord TextServiceInfo
  206.   (fComponent :Component)
  207.   (fItemName (:string 255))
  208. )
  209.  
  210. (def-mactype :TextServiceListHandle (find-mactype :handle))
  211. (def-mactype :TextServiceListPtr (find-mactype :pointer))
  212. (defrecord (TextServiceList :handle)
  213.   (fTextServiceCount :signed-integer)
  214.   (fServices  (:array :TextServiceInfo 1))
  215.   )
  216.       
  217. (defrecord ScriptLanguageRecord
  218.   (fScript :ScriptCode)
  219.   (fLanguage :LangCode)
  220. )
  221.           
  222. (def-mactype :ScriptLanguageSupportHandle (find-mactype :handle))
  223. (def-mactype :ScriptLanguageSupportPtr (find-mactype :pointer))
  224. (defrecord (ScriptLanguageSupport :handle)
  225.   (fScriptLanguageCount :signed-integer)
  226.   (fScriptLanguageArray (:Array :ScriptLanguageRecord 1))
  227.   )
  228.  
  229. (defrecord InterfaceTypeList (array (array :OSType 1)))
  230. (def-mactype :TSMDocumentID(find-mactype :pointer))
  231.     
  232. ;   Text Services Routines
  233.  
  234.  
  235. (deftrap _NewTSMDocument ((numOfInterface :signed-integer) (supportedInterfaceTypes :InterfaceTypeList) (idocID (:pointer :TSMDocumentID)) (refCon :signed-long))
  236.   (:stack :OSErr)
  237.   (:stack-trap #xA83D :d0 0 numOfInterface supportedInterfaceTypes idocID refCon))
  238.  
  239. (deftrap _DeleteTSMDocument ((idocID :TSMDocumentID))
  240.   (:stack :OSErr)
  241.   (:stack-trap #xAA54 :d0 1 idocID))
  242.  
  243. (deftrap _ActivateTSMDocument ((idocID :TSMDocumentID))
  244.   (:stack :OSErr)
  245.   (:stack-trap #xAA54 :d0 2 idocID))
  246.  
  247. (deftrap _DeactivateTSMDocument ((idocID :TSMDocumentID))
  248.   (:stack :OSErr)
  249.   (:stack-trap #xAA54 :d0 3 idocID))
  250.  
  251. (deftrap _TSMEvent ((event (:pointer :EventRecord)))
  252.   (:stack :Boolean)
  253.   (:stack-trap #xAA54 :d0 4 event))
  254.  
  255. (deftrap _TSMMenuSelect ((menuResult :signed-long))
  256.   (:stack :Boolean)
  257.   (:stack-trap #xAA54 :d0 5 menuResult))
  258.  
  259. (deftrap _SetTSMCursor ((mousePos :Point))
  260.   (:stack :Boolean)
  261.   (:stack-trap #xAA54 :d0 6 mousePos))
  262.  
  263. (deftrap _FixTSMDocument ((idocID :TSMDocumentID))
  264.   (:stack :OSErr)
  265.   (:stack-trap #xAA54 :d0 7 idocID))
  266.  
  267. (deftrap _GetServiceList ((numOfInterface :signed-integer) (supportedInterfaceTypes :InterfaceTypeList) (serviceInfo (:pointer :TextServiceListHandle)) (seedValue (:pointer :signed-long)))
  268.   (:stack :OSErr)
  269.   (:stack-trap #xAA54 :d0 8 numOfInterface supportedInterfaceTypes serviceInfo seedValue))
  270.  
  271. (deftrap _OpenTextService ((idocID :TSMDocumentID) (aComponent :Component) (aComponentInstance (:pointer :ComponentInstance)))
  272.   (:stack :OSErr)
  273.   (:stack-trap #xAA54 :d0 9 idocID aComponent aComponentInstance))
  274.  
  275. (deftrap _CloseTextService ((idocID :TSMDocumentID) (aComponentInstance :ComponentInstance))
  276.   (:stack :OSErr)
  277.   (:stack-trap #xAA54 :d0 10 idocID aComponentInstance))
  278.  
  279. (deftrap _SendAEFromTSMComponent ((theAppleEvent (:pointer :AppleEvent)) 
  280.                                    (reply (:pointer :AppleEvent)) (sendMode :AESendMode) 
  281.                                    (sendPriority :AESendPriority) (timeOutInTicks :signed-long) 
  282.                                    (idleProc :IdleProcPtr) (filterProc :EventFilterProcPtr))
  283.   (:stack :OSErr)
  284.   (:stack-trap #xAA54 :d0 11 theAppleEvent reply sendMode sendPriority
  285.                timeOutInTicks idleProc filterProc))
  286.  
  287. (deftrap _InitTSMAwareApplication nil
  288.   (:stack :OSErr)
  289.   (:stack-trap #xAA54 :d0 20))
  290.  
  291. (deftrap _CloseTSMAwareApplication nil
  292.   (:stack :OSErr)
  293.   (:stack-trap #xAA54 :d0 21))
  294.  
  295. (deftrap _SetDefaultInputMethod ((ts :Component) (slRecord (:pointer :ScriptLanguageRecord)))
  296.   (:stack :OSErr)
  297.   (:stack-trap #xAA54 :d0 12 ts slRecord))
  298.  
  299. (deftrap _GetDefaultInputMethod ((ts (:pointer :Component)) (slRecord (:pointer :ScriptLanguageRecord)))
  300.   (:stack :OSErr)
  301.   (:stack-trap #xAA54 :d0 13 ts slRecord))
  302.  
  303. (deftrap _SetTextServiceLanguage ((slRecord (:pointer :ScriptLanguageRecord)))
  304.   (:stack :OSErr)
  305.   (:stack-trap #xAA54 :d0 14 slRecord))
  306.  
  307. (deftrap _GetTextServiceLanguage ((slRecord (:pointer :ScriptLanguageRecord)))
  308.   (:stack :OSErr)
  309.   (:stack-trap #xAA54 :d0 15 slRecord))
  310.  
  311. (deftrap _UseInputWindow ((idocID :TSMDocumentID) (useWindow :Boolean))
  312.   (:stack :OSErr)
  313.   (:stack-trap #xAA54 :d0 16 idocID useWindow))
  314.  
  315. (deftrap _NewServiceWindow ((wStorage :pointer) (boundsRect :Rect) (title (:string 255))
  316.                              (visible :Boolean) (theProc :signed-integer) (behind :WindowPtr)
  317.                              (goAwayFlag :boolean) (ts :ComponentInstance) (window (:pointer :WindowPtr)))
  318.   (:stack :OSErr)
  319.   (:stack-trap #xAA54 :d0 17 wStorage boundsRect title visible theProc behind goAwayFlag ts window))
  320.  
  321. (deftrap _CloseServiceWindow ((window :WindowPtr))
  322.   (:stack :OSErr)
  323.   (:stack-trap #xAA54 :d0 18 window))
  324.  
  325. (deftrap _GetFrontServiceWindow ((window (:pointer :WindowPtr)))
  326.   (:stack :OSErr)
  327.   (:stack-trap #xAA54 :d0 19  window))
  328.  
  329. (deftrap _FindServiceWindow ((thePoint :Point) (theWindow (:pointer :WindowPtr)))
  330.   (:stack :signed-integer)
  331.   (:stack-trap #xAA54 :d0 23 thePoint theWindow))
  332.  
  333.  
  334. ;;    Low level Text Services routines
  335.  
  336. (deftrap _GetScriptLanguageSupport ((ts :ComponentInstance) (scriptHandle (:pointer :ScriptLanguageSupportHandle)))
  337.   (:stack :ComponentResult)
  338.   (:stack-trap #xA82A :d0 0 ts scriptHandle ((+ (ASH 1024 16) 1) :SIGNED-LONGINT)))
  339.  
  340. (deftrap _InitiateTextService ((ts :ComponentInstance))
  341.   (:stack :ComponentResult)
  342.   (:stack-trap #xA82A :d0 0 ts ((+ (ASH 0 16) 2) :SIGNED-LONGINT)))
  343.   
  344. (deftrap _TerminateTextService ((ts :ComponentInstance))
  345.   (:stack :ComponentResult)
  346.   (:stack-trap #xA82A :d0 0 ts ((+ (ASH 0 16) 3) :SIGNED-LONGINT)))
  347.  
  348. (deftrap _ActivateTextService ((ts :ComponentInstance))
  349.   (:stack :ComponentResult)
  350.   (:stack-trap #xA82A :d0 0 ts ((+ (ASH 0 16) 4) :SIGNED-LONGINT)))
  351.  
  352. (deftrap _DeactivateTextService ((ts :ComponentInstance))
  353.   (:stack :ComponentResult)
  354.   (:stack-trap #xA82A :d0 0 ts ((+ (ASH 0 16) 5) :SIGNED-LONGINT)))
  355.  
  356. (deftrap _TextServiceEvent ((ts :ComponentInstance) (numOfEvents :signed-integer) 
  357.                             (event (:pointer :EventRecord)))
  358.   (:stack :ComponentResult)
  359.   (:stack-trap #xA82A :d0 0 ts numOfEvents event ((+ (ASH 0 16) 6) :SIGNED-LONGINT)))
  360.  
  361. (deftrap _GetTextServiceMenu ((ts :ComponentInstance) (serviceMenu (:pointer :MenuHandle)))
  362.   (:stack :ComponentResult)
  363.   (:stack-trap #xA82A :d0 0 ts serviceMenu ((+ (ASH 0 16) 7) :SIGNED-LONGINT)))
  364.  
  365. (deftrap _TextServiceMenuSelect ((ts :ComponentInstance) (serviceMenu :MenuHandle) 
  366.                                  (item :signed-integer))
  367.   (:stack :ComponentResult)
  368.   (:stack-trap #xA82A :d0 0 ts serviceMenu item ((+ (ASH 0 16) 8) :SIGNED-LONGINT)))
  369.  
  370. (deftrap _FixTextService ((ts :ComponentInstance))
  371.   (:stack :ComponentResult)
  372.   (:stack-trap #xA82A :d0 0 ts ((+ (ASH 0 16) 9) :SIGNED-LONGINT)))
  373.  
  374. (deftrap _SetTextServiceCursor ((ts :ComponentInstance) (mousePos :Point))
  375.   (:stack :ComponentResult)
  376.   (:stack-trap #xA82A :d0 0 ts mousePos ((+ (ASH 0 16) 10) :SIGNED-LONGINT)))
  377.  
  378. (deftrap _HidePaletteWindows ((ts :ComponentInstance))
  379.   (:stack :ComponentResult)
  380.   (:stack-trap #xA82A :d0 0 ts ((+ (ASH 0 16) 12) :SIGNED-LONGINT)))
  381.  
  382.  
  383. (export '($kTSMVersion $kTextService $kInputMethodService $bTakeActiveEvent $bScriptMask $bLanguageMask
  384.           $bScriptLanguageMask $kCursorPosition $kRawText $kSelectedRawText $kConvertedText $kSelectedConvertedText
  385.           $kTextServiceClass $kUpdateActiveInputArea $kPos2Offset $kOffset2Pos $kShowHideInputWindow 
  386.           $keyAETSMDocumentRefcon $keyAEServerInstance $keyAETheData $keyAEScriptTag $keyAEFixLength 
  387.           $keyAEHiliteRange $keyAEUpdateRange $keyAEClauseOffsets $keyAECurrentPoint $keyAEDragging $keyAEOffset 
  388.           $keyAERegionClass $keyAEPoint $keyAEBufferSize $keyAERequestedType $keyAEMoveView $keyAELength
  389.           $keyAENextBody $keyAETextFont $keyAETextPointSize $keyAETextLineHeight $keyAETextLineAscent $keyAEAngle
  390.           $keyAELeftSide $keyAEShowHideInputWindow $keyAEPinRange $typeComponentInstance $typeTextRangeArray
  391.           $typeOffsetArray $typeIntlWritingCode $typeQDPoint $typeAEText $typeText $typeTextRange
  392.           $tsmComponentNoErr $tsmUnsupScriptLanguageErr $tsmInputMethodNotFoundErr $tsmNotAnAppErr
  393.           $tsmAlreadyRegisteredErr $tsmNeverRegisteredErr $tsmInvalidDocIDErr $tsmTSMDocBusyErr 
  394.           $tsmDocNotActiveErr $tsmNoOpenTSErr $tsmCantOpenComponentErr $tsmTextServiceNotFoundErr
  395.           $tsmDocumentOpenErr $tsmUseInputWindowErr $tsmTSHasNoMenuErr $tsmTSNotOpenErr 
  396.           $tsmComponentAlreadyOpenErr $tsmInputMethodIsOldErr $tsmScriptHasNoIMErr $tsmUnsupportedTypeErr
  397.           $tsmUnknownErr $kTSMOutsideOfBody $kTSMInsideOfBody $kTSMInsideOfActiveInputArea $kNextBody
  398.           $kPreviousBody $errOffsetInvalid $errOffsetIsOutsideOfView $errTopOfDocument $errTopOfBody
  399.           $errEndOfDocument $errEndOfBody))
  400.  
  401. (provide-interface 'textservices)